<?php

class Eleven_Model_Announcement extends CMS_Model_Acl_Abstract
{
	public function getAnnouncements($paged=false,$order=null)
	{
		return $this->getResource('Announcement')->getAnnouncements($paged, $order);
	}
	
	public function getIndexAnnouns($total=7)
	{
	    return $this->getResource('Announcement')->getIndexAnnouns($total);
	}
	
	public function getAnnounceById($id)
	{
		$id = (int) $id;
        
        return $this->getResource('Announcement')->getAnnounceById($id);
	}
	
	public function savePost($post)
	{
		$form = $this->getForm('announcementPost');
       	return $this->_save($form, $post);
	}
	
	public function saveEdit($post)
	{
	    $form = $this->getForm('announcementEdit');
       	return $this->_save($form, $post);
	}
	
	protected function _save($form, $info, $defaults=array())
    {       
        if (!$form->isValid($info)) {
            return false;
        }

        // get filtered values
        $data = $form->getValues();

        $post = array_key_exists('id', $data) ?
            $this->getResource('Announcement')->getAnnounceById($data['id']) : null;
		
        $data['publishdate'] = time();
        return $this->getResource('Announcement')->saveRow($data, $post);
    }
    
    public function deleteAnnounceById($id)
	{
		$id = (int) $id;
        
        return $this->getResource('Announcement')->deleteAnnounceById($id);
	}
/**
     * @param CMS_Acl_Interface CMS_Acl_Interface CMS_Acl_Interface CMS_Acl_Interface $acl
     */
    public function setAcl (CMS_Acl_Interface $acl)
    {
        if (!$acl->has($this->getResourceId()))
        {
            $acl->add($this)
                ->allow('Guest', $this, array('index','view'))
                ->allow('Student', $this, array('post','save'))
                ->allow('Teacher');
                
            $this->_acl = $acl;
            return $this;
        }
    }
    
    public function setTops($tops, $isCancel)
    {
        return $this->getResource('Announcement')->setTops($tops, $isCancel);
    }

/**
     * 
     */
    public function getAcl ()
    {
        if (null === $this->_acl)
        {
            $this->setAcl(new Eleven_Model_Acl());
        }
        
        return $this->_acl; 
    }

/**
     * 
     */
    public function getResourceId ()
    {
        return 'Announcement';
    }



}

?>